/**未遂事故的列表页面 */
<template>
  <div class="app-container">

    <div class="filter-container">
      未遂事故题目：   <el-input v-model="listQuery.faultTitle" placeholder="题目" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      未遂事故地点：     <el-input v-model="listQuery.faultLocation" placeholder="地点" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      未遂事故发生开始时间： <el-input v-model="listQuery.startDate" placeholder="开始时间" type="date" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      未遂事故发生结束时间： <el-input v-model="listQuery.endDate" placeholder="结束时间" type="date" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        查询
      </el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
        新增
      </el-button>
      <el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download" @click="handleDownload">
        Export
      </el-button>
      <!--
      <el-checkbox v-model="showReviewer" class="filter-item" style="margin-left:15px;" @change="tableKey=tableKey+1">
        reviewer
      </el-checkbox> -->
    </div>

    <!-- Note that row-key is necessary to get a correct row order. -->
    <el-table ref="dragTable" v-loading="listLoading" :data="list" row-key="id" border fit highlight-current-row style="width: 100%">

      <el-table-column width="180px" align="center" label="未遂事故单编号" prop="faultId" />

      <el-table-column min-width="300px" label="未遂事故题目">
        <template slot-scope="scope">
          <span @click="handleDetail(scope.row)">{{ scope.row.faultTitle }}</span></template>
      </el-table-column>
      <el-table-column min-width="300px" label="未遂事故类型">
        <template slot-scope="scope">
          <span @click="handleDetail(scope.row)">{{ scope.row.fault_TypeId }}</span></template>
      </el-table-column>
      <el-table-column width="110px" align="center" label="发生地点">
        <template slot-scope="scope">
          <span @click="handleDetail(scope.row)">{{ scope.row.faultLocation }}</span></template>
      </el-table-column>
      <el-table-column width="100px" label="发生时间">

        <template slot-scope="scope">

          <span>{{ scope.row.faultTime | parseTime('{y}-{m}-{d} {h}:{i}') }}</span></template>
      </el-table-column>
      <el-table-column align="center" label="发现人" width="95">
        <template slot-scope="scope">
          <span @click="handleDetail(scope.row)">{{ scope.row.faultUserCode.userName }}</span></template>
      </el-table-column>
      <el-table-column class-name="status-col" label="所属Team" width="110">
        <template slot-scope="scope">
          <span @click="handleDetail(scope.row)">{{ scope.row.faultTeam.deptName }}</span></template>
      </el-table-column>
      <el-table-column class-name="status-col" label="附件" width="110">
        <template v-if="scope.row.faultFileId==1" slot-scope="scope">
          <el-button type="primary" size="small" @click="handlegetFile(scope.row)">附件</el-button>
        </template></el-table-column>
      <el-table-column align="center" label="裁决状态" width="80" prop="faultSatus">
        <template slot-scope="scope">
          <span v-if="scope.row.faultSatus==1">申请中</span>
          <span v-if="scope.row.faultSatus==0">已删除</span>
          <span v-if="scope.row.faultSatus==2">已裁决</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="230">
        <template v-if="scope.row.faultSatus==2" slot-scope="scope">

          <el-button type="primary" size="small" @click="handleEdit(scope.row)">修改</el-button>
          <el-button type="danger" size="small" @click="handleDelete(scope.row)">删除</el-button>
        <!-- <el-button type="danger" size="small" @click="handleScore(scope.row)">评分</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="fechData" />

    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
      <el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="150px" style="width: 700px; margin-left:50px;">

        <el-form-item label="未遂事故单题目" prop="faultTitle">
          <el-input v-model="temp.faultTitle" />
        </el-form-item>
        <el-form-item label="未遂事故发生地点" prop="faultLocation">

          <el-input v-model="temp.faultLocation" />

        </el-form-item>
        <el-form-item label="未遂事故发生内容" prop="faultContent">
          <markdown-editor ref="markdownEditor" v-model="temp.faultContent" :options="{hideModeSwitch:true,previewStyle:'tab'}" height="300px" />
          <!-- <markdown-editor v-model="temp.faultContent" height="300px" /> -->

        </el-form-item>
        <el-form-item label="未遂事故发生原因" prop="faultReason">
          <markdown-editor ref="markdownEditor" v-model="temp.faultReason" :options="{hideModeSwitch:true,previewStyle:'tab'}" height="300px" />
          <!-- <markdown-editor v-model="temp.faultReason" height="300px" /> -->
          <!-- <el-input v-model="temp.faultReason" /> -->
        </el-form-item>
        <el-form-item label="未遂事故类型" prop="faulttype">
          <el-drag-select v-model="faultType" style="width:500px;" multiple placeholder="请选择事故类型">
            <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
          </el-drag-select>

        </el-form-item>
        <el-form-item label="未遂事故发生原因" prop="faultadvice">
          <markdown-editor ref="markdownEditor" v-model="temp.faultadvice" :options="{hideModeSwitch:true,previewStyle:'tab'}" height="300px" />
          <!-- <markdown-editor v-model="temp.faultadvice" height="300px" /> -->
          <!-- <el-input v-model="temp.faultadvice" /> -->
        </el-form-item>
        <el-form-item label="对策" prop="faultFun">
          <markdown-editor ref="markdownEditor" v-model="temp.faultFun" :options="{hideModeSwitch:true,previewStyle:'tab'}" height="300px" />
          <!-- <markdown-editor v-model="temp.faultFun" height="300px" /> -->
          <!-- <el-input v-model="temp.faultadvice" /> -->
        </el-form-item>

        <el-form-item label="未遂事故单创建时间" prop="faultWriteTime">
          <el-date-picker v-model="temp.faultWriteTime" type="datetime" value-format="yyyy-MM-dd hh:mm:ss" placeholder="请选择日期" />
          <!-- <el-input v-model="temp.faultTime " /> -->
        </el-form-item>
        <el-form-item label="未遂事故发生时间" prop="faultTime">
          <el-date-picker v-model="temp.faultTime" type="datetime" value-format="yyyy-MM-dd hh:mm:ss" placeholder="请选择日期" />
          <!-- <el-input v-model="temp.faultTime " /> -->
        </el-form-item>
        <el-form-item label="未遂事故发现人" prop="faultUserCode">
          <el-input v-model="userName" readonly="readonly" placeholder="不填" />
        </el-form-item>
        <!-- <el-form-item label="未遂事故发现人" prop="faultUserCode">

          <el-autocomplete
            v-model="userName"
            class="el-input"
            :fetch-suggestions="userSearchAsync"
            placeholder="请输入工号"
            :trigger-on-focus="false"
            @select="handleSelect"
          />
        </el-form-item>-->

        <el-form-item label="未遂事故所属Team" prop="faultTeam">

          <el-autocomplete
            v-model="deptName"
            class="el-input"
            :fetch-suggestions="deptSearchAsync"
            placeholder="请输入部门"
            :trigger-on-focus="false"
            @select="handleSelectTeam"
          />
        </el-form-item>
        <el-form-item label="附件上传">
          <ul>
            <div style="margin-left:100px">
              <el-upload
                v-model="file"
                class="upload-demo"
                action="http://localhost:8080/ehs_files/upload"
                :on-change="handleChange"
                :on-success="uploadfile"
              ><el-button size="big" type="primary">点击上传</el-button>

              </el-upload>
            </div>
          </ul>.

        </el-form-item>

        <!-- <el-form-item label="未遂事故所属Team">
          <el-select v-model="deptName" class="filter-item" placeholder="Please select">
            <el-option v-for="item in deptlist" :key="item" :label="item" :value="item" />
          </el-select>
        </el-form-item> -->

        <!-- <div v-if="this.dialogStatus=='score'">
          <el-form-item label="评分人">

            <el-select v-model="scoreName" class="filter-item" placeholder="Please select">
              <el-option v-for="item in scorelist" :key="item" :label="item" :value="item" />
            </el-select>
          </el-form-item>
        </div> -->

        <!-- <div v-if="this.dialogStatus=='score'">
          <el-form-item label="评分" prop="score">
            <el-input v-model="temp.score" />
          </el-form-item>
        </div>
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">
          取消
        </el-button>
        <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
          提交
        </el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import ElDragSelect from '@/components/DragSelect' // base on element-ui
import MarkdownEditor from '@/components/MarkdownEditor'
import { fetchFaultList, deleteFaultList, editFault, fetchAllCount, getPersonList, getDeptList, createFault, getDeptByName } from '@/api/fault'
import Sortable from 'sortablejs'
import { parseTime } from '@/utils'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { getuserbyemp } from '@/api/user'
import { getFileName } from '@/api/file'

export default {
  name: 'Fault',
  components: { Pagination, MarkdownEditor, ElDragSelect },
  directives: { waves },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }

  },
  data() {
    return {
      id: '',
      type: 'ehs_fault',
      file: null,
      limitNum: 1,
      formLabelWidth: '80px',
      // form: {
      //   file: '',
      //  file1: ''
      // },
      // filesId: '',
      fileList: [],
      faultType: [],
      options: [{
        value: '不注意',
        label: '不注意'
      }, {
        value: '未遵守章程',
        label: '未遵守章程'
      }, {
        value: '管理不当',
        label: '管理不当'
      }, {
        value: '操作失误',
        label: '操作失误'
      }, {
        value: '设备缺陷',
        label: '设备缺陷'
      }, {
        value: '信息共享',
        label: '信息共享'
      }, {
        value: '其他',
        label: '其他'
      }],
      faultType1: null,
      list: null,
      total: 0,
      listLoading: true,
      editList: null,
      deptName: null,
      userName: null,
      deptId: null,
      userId: null,
      sortable: null,
      oldList: [],
      newList: [],
      // 参数条件
      listQuery: {
        page: 1,
        limit: 20,
        faultTitle: null,
        faultLocation: null,
        startDate: null,
        endDate: null
      },
      personlist: null,
      deptlist: null,
      scorelist: ['yang', 'liu', 'zhang', 'zhao'],
      temp: {
        faultId: '',
        faultTitle: '',
        faultLocation: '',
        faultContent: '',
        faultReason: '',
        faultFun: '',
        faultRemark: '',
        faultadvice: '',
        faultWriteTime: '',
        faultTime: '',
        faultSatus: 1,
        faultTeam: '',
        faultFileId: '',
        faultUserCode: ''
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '修改',
        create: '新增',
        detail: '明细'
        // score: '评价'
      },
      dialogPvVisible: false,
      pvData: [],
      rules: {
        type: [{ required: true, message: 'type is required', trigger: 'change' }],
        // timestamp: [{ type: 'faultTime', required: true, message: 'timestamp is required', trigger: 'change' }],
        faultTitle: [{ required: true, message: '未遂事故题目不能为空', trigger: 'blur' }],
        faultLocation: [{ required: true, message: '未遂事故地点不能为空', trigger: 'blur' }],
        faultWriteTime: [{ required: true, message: '创建时间不能为空', trigger: 'blur' }],
        faultTime: [{ required: true, message: '未遂事故发生时间不能为空', trigger: 'blur' }],
        // faultUserCode: [{ required: true, message: '创建人不能为空', trigger: 'blur' }],
        faultTeam: [{ required: true, message: '创建部门不能为空', trigger: 'change' }]

      },
      downloadLoading: false
    }
  },
  created() {
    this.fechData()
  },
  methods: {
    fechData() {
      getPersonList().then(response => {
        this.personlist = response.listName
      })
      getDeptList().then(response => {
        this.deptlist = response.listName
      })
      fetchAllCount().then(response => {
        this.total = response.count
      })
      fetchFaultList(this.listQuery).then(response => {
        this.listLoading = true
        this.list = response.ehsfaultList

        this.showList = response.ehsfaultList
        // .log('888888888888888' + response.ehsfaultList)
        this.listLoading = false
        // this.oldList = response.map(v => v.id)
      //  this.newList = response.map(v => v.id).slice()
      })
    },
    handleCreate() {
      this.resetTemp()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    createData() {
      // alert(this.dialogStatus)
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const userName = this.userName

          const deptName = this.deptName

          const faultType1 = this.faultType.toString()
          // alert(this.temp.faultTime)
          // alert(this.temp.faultWriteTime)
          if (this.file == null) {
            this.temp.author = 'vue-element-admin'

            const query = { faultfun: this.temp.faultFun, faultType1: faultType1, faultTime: this.temp.faultTime, faultWriteTime: this.temp.faultWriteTime, faultadvice: this.temp.faultadvice, faultContent: this.temp.faultContent, faultReason: this.temp.faultReason, faultFun: this.temp.faultFun, faultLocation: this.temp.faultLocation, faultTitle: this.temp.faultTitle, userName: userName, deptName: deptName, userId: this.userId, deptId: this.deptId }
            createFault(query).then(() => {
              this.list.unshift(this.temp.userName)
              this.dialogFormVisible = false
              this.$notify({
                title: 'Success',
                message: 'Created Successfully',
                type: 'success',
                duration: 2000
              })
            })
          } else {
            this.temp.author = 'vue-element-admin'

            const query = { fileId: this.file.filesId, faultType1: faultType1, faultTime: this.temp.faultTime, faultWriteTime: this.temp.faultWriteTime, faultadvice: this.temp.faultadvice, faultContent: this.temp.faultContent, faultReason: this.temp.faultReason, faultFun: this.temp.faultFun, faultLocation: this.temp.faultLocation, faultTitle: this.temp.faultTitle, userName: userName, deptName: deptName, userId: this.userId, deptId: this.deptId }
            createFault(query).then(() => {
              this.list.unshift(this.temp.userName)
              this.dialogFormVisible = false
              this.$notify({
                title: 'Success',
                message: 'Created Successfully',
                type: 'success',
                duration: 2000
              })
            })
          }

          location.reload()
        }
      })
    },

    handleDownload() {
      // alert('excel导出')
      // console.log('excel+输出打印数据' + this.list.faultType1)
      this.downloadLoading = true
      import('@/vendor/Export2Excel').then(excel => {
        const tHeader = ['未遂事故编号', '未遂事故题目', '未遂事故类型', '发生地点', '未遂事故发生时间', '未遂事故创建人', '创建人部门']
        const filterVal = ['faultId', 'faultTitle', 'fault_TypeId', 'faultLocation', 'faultTime', 'faultUserCode', 'faultTeam']

        const data = this.formatJson(filterVal, this.list)
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: 'table-list'
        })
        this.downloadLoading = false
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        if (j === 'timestamp') {
          return parseTime(v[j])
        }
        if (j === 'faultTime') {
          return parseTime(v[j])
        }
        if (j === 'faultWriteTime') {
          return parseTime(v[j])
        }
        if (j === 'faultUserCode') {
          return v[j].userName
        } if (j === 'faultTeam') {
          return v[j].deptName
        } if (j === 'fault_TypeId') {
          return v[j]
        } else {
          return v[j]
        }
      }))
    },
    showReviewer() {

    },
    async handleSelect(u) {
      this.userName = u.userName
      this.userId = u.userId
      // alert(this.userId)
    },
    async handleSelectTeam(u) {
      this.deptName = u.deptName
      this.deptId = u.deptId
      this.temp.faultTeam = '' + this.deptName
      // alert(this.deptId)
    },
    handleFilter() {
      this.listQuery.page = 1
      this.fechData()
    },
    resetTemp() {
      this.temp = {
        faultId: undefined,

        faultTitle: '',
        faultLocation: '',
        faultContent: '',
        faultReason: '',
        faultFun: '',
        faultRemark: '',
        faultadvice: '',
        faultWriteTime: '',
        faultTime: '',
        faultSatus: 1,
        faultTeam: '',
        faultFileId: '',
        faultUserCode: ''
      }
    },
    handleDelete(row) {
      deleteFaultList(row.faultId).then(response => {

      })
      // 刷新页面
      location.reload()
    },
    handlegetFile(row) {
      // alert(row.faultId)
      this.id = row.faultId
      this.type = 'ehs_fault'
      // // 1.先创建一个a标签
      // const a = document.createElement('a')
      // // 2.给a标签的href赋上下载地址
      // a.href = 'http://localhost:8080/ehs_files/getfile?id=' + this.id + '&type=' + this.type
      // // 3.让a标签不显示在视图中
      // a.style.display = 'none'
      // // 4.将a标签append到文档中
      // document.body.appendChild(a)
      // // a.setAttribute('download', a.fileName)
      // a.download = '附件'
      // console.log('MMMMMMMMMMMMMMMMMMMM' + a)
      // // 5.a标签自点击
      // a.click()
      // // 6.点击下载后，销毁这个节点
      // document.body.removeChild(a)

      const query = { id: this.id, type: this.type }
      // const query1 = JSON.parse(JSON.stringify(query))
      console.log('query is  ' + query)
      // 获取附件名称

      getFileName(query).then(response => {
        this.file = response.file
        console.log('MMMMMMMMMMMMMMMMMMMMMMMM' + this.file)
        const url = 'http://localhost:8080/ehs_files/getfile?id=' + this.id + '&type=' + this.type // 创建下载链接
        const link = document.createElement('a') // 创建a标签
        link.style.display = 'none' // 将a标签隐藏
        link.href = url // 给a标签添加下载链接
        link.setAttribute('download', this.file.filename) // 此处注意，要给a标签添加一个download属性，属性值就是文件名称 否则下载出来的文件是没有属性的，空白白
        document.body.appendChild(link)
        link.click() // 执行a标签
      })
      // getFile(query).then(response => {
      //   const cookie = response.headers.cookie
      //   console.log(cookie)
      //   this.file1 = response.file

      // })
    },
    handleEdit(row) {
      const row1 = JSON.parse(JSON.stringify(row))
      this.temp1 = Object.assign({}, row1) // copy obj

      this.temp.faultId = this.temp1.faultId
      if (this.temp1.fault_TypeId != null) {
        this.faultType = this.temp1.fault_TypeId.split(',')
      }

      this.userName = this.temp1.faultUserCode.userName
      this.deptName = this.temp1.faultTeam.deptName
      this.temp.timestamp = new Date(this.temp.timestamp)
      this.temp.faultTitle = this.temp1.faultTitle
      this.temp.faultLocation = this.temp1.faultLocation
      this.temp.faultContent = this.temp1.faultContent
      this.temp.faultTime = this.temp1.faultTime
      this.temp.faultWriteTime = this.temp1.faultWriteTime
      this.temp.faultTeam = this.temp1.faultTeam
      this.temp.faultReason = this.temp1.faultReason
      this.temp.faultFun = this.temp1.faultFun
      this.temp.faultRemark = this.temp1.faultRemark
      this.temp.faultadvice = this.temp1.faultadvice
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    updateData() {
      // alert(this.dialogStatus)
      if (this.dialogStatus === 'detail') {
        location.reload()
      } else if (this.dialogStatus === 'update') {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            const tempData = Object.assign({}, this.temp)
            const query1 = JSON.parse(JSON.stringify(tempData))
            const faultType1 = this.faultType.join(',')

            tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
            if (this.file == null) {
              const query = {
                faultId: query1.faultId,
                faultTitle: query1.faultTitle,
                faultLocation: query1.faultLocation,
                faultContent: query1.faultContent,
                faultReason: query1.faultReason,
                faultFun: query1.faultFun,
                faultWriteTime: query1.faultWriteTime,
                faultTime: query1.faultTime,
                faultRemark: query1.faultRemark,
                faultSatus: 2,
                faultType2: faultType1,
                userName: this.userName,
                deptName: this.deptName,
                faultadvice: query1.faultadvice }
              editFault(query).then(response => {
                this.obj = response
                this.faultId = response.faultId
                this.faultTitle = response.faultTitle
              })
            } else {
              const query = {
                fileName: this.file.name,
                fileId: this.file.filesId,
                faultId: query1.faultId,
                faultTitle: query1.faultTitle,
                faultLocation: query1.faultLocation,
                faultContent: query1.faultContent,
                faultReason: query1.faultReason,
                faultFun: query1.faultFun,
                faultWriteTime: query1.faultWriteTime,
                faultTime: query1.faultTime,
                faultRemark: query1.faultRemark,
                faultSatus: 2,
                faultType2: faultType1,
                userName: this.userName,
                deptName: this.deptName,
                faultadvice: query1.faultadvice }
              editFault(query).then(response => {
                this.obj = response
                this.faultId = response.faultId
                this.faultTitle = response.faultTitle
              })
            }
            // 刷新页面
            location.reload()
          }
        })
      }
    },
    handleDetail(row) {
      const row1 = JSON.parse(JSON.stringify(row))

      this.userName = row1.faultUserCode.userName
      this.deptName = row1.faultTeam.deptName
      this.temp = Object.assign({}, row1) // copy obj

      this.faultType = this.temp.fault_TypeId.split(',')
      this.temp.timestamp = new Date(this.temp.timestamp)
      this.dialogStatus = 'detail'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    handleScore(row) {
      const row1 = JSON.parse(JSON.stringify(row))
      this.temp1 = Object.assign({}, row1) // copy obj

      this.faultType = this.temp1.fault_TypeId.split(',')
      this.userName = this.temp1.faultUserCode.userName
      this.deptName = this.temp1.faultTeam.deptName
      this.temp.timestamp = new Date(this.temp.timestamp)
      this.temp.faultTitle = this.temp1.faultTitle
      this.temp.faultLocation = this.temp1.faultLocation
      this.temp.faultContent = this.temp1.faultContent

      this.temp.faultReason = this.temp1.faultReason
      this.temp.faultFun = this.temp1.faultFun
      this.temp.faultRemark = this.temp1.faultRemark
      this.temp.faultadvice = this.temp1.faultadvice

      this.dialogStatus = 'score'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    getHtml() {
      this.faultContent = this.$refs.markdownEditor.getHtml()
      // console.log(this.faultContent)
    },

    async userSearchAsync(queryString, callback) {
      var list = []
      const { userList } = await getuserbyemp(queryString)
      userList.forEach(r => {
        var tem_obj = {}
        tem_obj.value = r.empNo + '-' + r.userName + '-' + r.userId
        tem_obj.userName = r.userName
        tem_obj.userId = r.userId
        list.push(tem_obj)
      })

      callback(list)
    },
    async deptSearchAsync(queryString, callback) {
      var list = []
      const { deptList } = await getDeptByName(queryString)
      deptList.forEach(r => {
        var tem_obj = {}
        tem_obj.value = r.deptId + '-' + r.deptName
        tem_obj.deptName = r.deptName
        tem_obj.deptId = r.deptId
        list.push(tem_obj)
      })

      callback(list)
    },
    setSort() {
      const el = this.list[0]

      this.sortable = Sortable.create(el, {
        ghostClass: 'sortable-ghost', // Class name for the drop placeholder,
        setData: function(dataTransfer) {
          // to avoid Firefox bug
          // Detail see : https://github.com/RubaXa/Sortable/issues/1012
          dataTransfer.setData('Text', '')
        },
        onEnd: evt => {
          const targetRow = this.list.splice(evt.oldIndex, 1)[0]
          this.list.splice(evt.newIndex, 0, targetRow)

          // for show the changes, you can delete in you code
          const tempIndex = this.newList.splice(evt.oldIndex, 1)[0]
          this.newList.splice(evt.newIndex, 0, tempIndex)
        }
      })
    },
    handleChange() {

    },
    uploadfile(response, file, fileList) {
      // alert('111')
      this.file = response.file
    }

  }

}
</script>

<style>
.sortable-ghost{
  opacity: .8;
  color: #fff!important;
  background: #42b983!important;
}
</style>

<style scoped>
.icon-star{
  margin-right:2px;
}
.drag-handler{
  width: 20px;
  height: 20px;
  cursor: pointer;
}
.show-d{
  margin-top: 15px;
}
</style>
